package com.lj.ljminsu.wk.controller;

import com.lj.ljminsu.wk.bean.JsonResultVo;
import com.lj.ljminsu.wk.bean.UpawayBean;
import com.lj.ljminsu.wk.service.IQueryHouseListService;
import com.lj.ljminsu.wk.service.IUpdateHouseStateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("house")
public class UpawayController {

    @Resource
    private IQueryHouseListService iQueryHouseListService;
    @Resource
    private IUpdateHouseStateService iUpdateHouseStateService;


    /*查询房屋信息*/
    @RequestMapping("house-list")
    @ResponseBody
    public List<UpawayBean> queryHouseList() {

        List<UpawayBean> houseList = iQueryHouseListService.queryHouseList();

        return houseList;
    }

    /*上下架*/
    @RequestMapping("on-off-line")
    @ResponseBody
    public JsonResultVo goodsOnlineOrOffline(Integer flag, String ids) {
        JsonResultVo jsonResultVo = new JsonResultVo();
        try {
            iUpdateHouseStateService.updateHouseState(flag,ids);
            jsonResultVo.setCode(0);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResultVo.setCode(1);
        }


        return jsonResultVo;
    }


}
